#ifndef FLASHEXECUTOR_H
#define FLASHEXECUTOR_H

#include <cstdint>
#include "candriver.h"
#include "qjsonarray.h"
#include "qtimer.h"
#include "udsclient.h"

typedef struct
{
    uint8_t blockIdx;
    uint32_t dataIdx;
    uint32_t tranSize;
    uint32_t rqstAddr;
    uint32_t rqstSize;
    uint32_t caclCrc;
    uint32_t receCrc;
    uint8_t transData[0x40000];
} sActionFlow;

extern sActionFlow ActionFlow;

class FlashExecutor : public QObject
{
    Q_OBJECT

public:
    FlashExecutor();
    void Initialization();
    void TxProcessHandle();
    void Tick100ms();
    void handleRxMsg(sCANObj msg);
    void setAppPath(QString Path);
    static QString getAppPath();

signals:
    void updateS3Timer();
    void updateVersion(uint8_t *str, uint8_t strLen);
    void updateListMsg(QString msg, uint8_t type);

public:
    QJsonArray flashInfor;
    bool u8RunningFlag = false;
    bool u8ReceSuccFlag = false;
    uint8_t u8TotalStep = 0;
    uint8_t u8CurrStep;
    uint16_t S3TimerTick;
    UdsClient udsClient;
    static QString AppPath;

private:
    QTimer S3Timer;
};

#endif // FLASHEXECUTOR_H
